import pandas as pd
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
data =  pd.read_csv("data/automobile_advertisement.csv")
print(data)
print(data.shape)


x = data.iloc[:,0].values.reshape(-1, 1)  # 只取第一列作为特征，并转为二维数组
y = data.iloc[:,-1]
x_test = [[7]]

print(f"hhh",x)
# print(y)

model = LinearRegression()
model.fit(x,y)
print(f"最终的斜率:{model.coef_}")  # [0.92942177]
print(f"最终的截距:{model.intercept_}")  # -93.27346938775517

predict = model.predict(x_test)
print("预测值是:",predict)
plt.plot(x, y)

plt.plot(x, y, label='y = 5x + 10', color='blue', linewidth=2)


plt.grid(True)
plt.show()